#ifndef __MACRO_H
#define __MACRO_H

#include <stdlib.h>
#include <string.h>
#include <flgrCoreData.h>
#include <flgrCoreDataIO.h>
#include <flgrCoreNhbManage.h>

#ifndef EXIT_FAILURE
#define EXIT_FAILURE 1
#endif

#define PRINT_TEST_NUMBER(nbtest)   printf("\033[34m------>%d tests successfully executed\033[0m\n",nbtest);


#define EXIT_ON_ERROR(function)						\
  c = function();							\
  if(c<0) {								\
    POST_ERROR("\033[31m------> Test failure in <%s>\033[0m\n",		\
	       #function);						\
    exit(EXIT_FAILURE);							\
  }									\
  nbtest+=c;								\

#define check_ret(ret,VAL)					\
  printf("%s",__FUNCTION__);					\
								\
  if(ret!=VAL) {						\
    printf(": failed code = %s\n",getStringErrorCode(ret));	\
    return -1;							\
  }else printf(": ok\n");					\



#define check_and_display_vector(vecref,vec,ret) \
  if(_check_and_display_vector(vecref,vec,ret,__FUNCTION__)==-1) return -1

#define check_and_display_data1d(imgref,img,ret) \
  if(_check_and_display_data1d(imgref,img,ret,__FUNCTION__)==-1) return -1

#define check_and_display_data2d(imgref,img,ret) \
  if(_check_and_display_data2d(imgref,img,ret,__FUNCTION__)==-1) return -1

#define check_and_display_box1d(extrref, extr, ret) \
  if(_check_and_display_box1d(extrref, extr, ret,__FUNCTION__)==-1) return -1

#define check_and_display_box2d(extrref, extr, ret) \
  if(_check_and_display_box2d(extrref, extr, ret,__FUNCTION__)==-1) return -1



extern const char *getStringErrorCode(FLGR_Ret ret);
extern void display_vector(FLGR_Vector *vec);
extern void display_vector_false(FLGR_Vector *vec);

extern void print_vector(FLGR_Vector *vec);
extern void print_vector_false(FLGR_Vector *vec);
extern int check_vector(FLGR_Vector *vec1, FLGR_Vector *vec2);
extern int _check_and_display_vector(FLGR_Vector *vecref,FLGR_Vector *vec,FLGR_Ret ret, const char *calling_fct);

extern void print_data1d(FLGR_Data1D *dat);
extern void print_data1d_false(FLGR_Data1D *datref, FLGR_Data1D *dat);
extern int check_data1d(FLGR_Data1D *datref, FLGR_Data1D *dat);
extern int _check_and_display_data1d(FLGR_Data1D *datref, FLGR_Data1D *dat, FLGR_Ret ret, const char *calling_fct);

extern void print_data2d(FLGR_Data2D *dat);
extern void print_data2d_false(FLGR_Data2D *datref, FLGR_Data2D *dat);
extern int check_data2d(FLGR_Data2D *datref, FLGR_Data2D *dat);
extern int _check_and_display_data2d(FLGR_Data2D *imgref, FLGR_Data2D *img, FLGR_Ret ret, const char *calling_fct);

extern void print_neighbor_box1d(FLGR_NhbBox1D *extr);
extern int check_neighbor_box1d(FLGR_NhbBox1D *extr1, FLGR_NhbBox1D *extr2);
extern int _check_and_display_box1d(FLGR_NhbBox1D *extrref, FLGR_NhbBox1D *extr, FLGR_Ret ret,const char *calling_fct);

extern void print_neighbor_box2d(FLGR_NhbBox2D *extr);
extern int check_neighbor_box2d(FLGR_NhbBox2D *extr1, FLGR_NhbBox2D *extr2);
extern int _check_and_display_box2d(FLGR_NhbBox2D *extrref, FLGR_NhbBox2D *extr, FLGR_Ret ret,const char *calling_fct);




#endif
